# OA系统登录流程简单测试
Write-Host "开始测试OA系统登录流程..." -ForegroundColor Green

# 测试配置
$baseUrl = "http://localhost:8000"
$loginEndpoint = "/api/auth/login"
$username = "liuhui"
$password = "zhilv2023"

Write-Host "测试配置信息:" -ForegroundColor Yellow
Write-Host "  Base URL: $baseUrl" -ForegroundColor Yellow
Write-Host "  Login Endpoint: $loginEndpoint" -ForegroundColor Yellow

# 测试后端API连接
Write-Host "`n1. 测试后端API连接..." -ForegroundColor Cyan

try {
    $headers = @{
        "Content-Type" = "application/json"
    }
    
    $body = @{
        username = $username
        password = $password
    } | ConvertTo-Json

    $response = Invoke-WebRequest -Uri "$baseUrl$loginEndpoint" -Method POST -Body $body -Headers $headers -TimeoutSec 10
    
    if ($response.StatusCode -eq 200) {
        Write-Host "  OK API连接成功" -ForegroundColor Green
        $responseData = $response.Content | ConvertFrom-Json
        
        if ($responseData.code -eq 0) {
            Write-Host "  OK 登录成功，消息: $($responseData.msg)" -ForegroundColor Green
            Write-Host "  OK Token长度: $($responseData.data.token.Length)" -ForegroundColor Green
        } else {
            Write-Host "  XX 登录失败，错误码: $($responseData.code)，消息: $($responseData.msg)" -ForegroundColor Red
        }
    } else {
        Write-Host "  XX API连接失败，状态码: $($response.StatusCode)" -ForegroundColor Red
    }
} catch {
    Write-Host "  XX API连接异常: $($_.Exception.Message)" -ForegroundColor Red
}

# 验证前端文件
Write-Host "`n2. 验证前端文件..." -ForegroundColor Cyan

$distPath = "d:\phpstudy_pro\WWW\oa.laizone.com\migration\frontend\dist"
if (Test-Path $distPath) {
    Write-Host "  OK 前端构建目录存在" -ForegroundColor Green
} else {
    Write-Host "  XX 前端构建目录不存在" -ForegroundColor Red
}

# 检查关键组件
Write-Host "`n3. 检查关键组件..." -ForegroundColor Cyan

$loginVuePath = "d:\phpstudy_pro\WWW\oa.laizone.com\migration\frontend\src\views\Login.vue"
$routerPath = "d:\phpstudy_pro\WWW\oa.laizone.com\migration\frontend\src\router\index.ts"
$dashboardPath = "d:\phpstudy_pro\WWW\oa.laizone.com\migration\frontend\src\views\Dashboard.vue"

if (Test-Path $loginVuePath) {
    Write-Host "  OK Login.vue存在" -ForegroundColor Green
} else {
    Write-Host "  XX Login.vue不存在" -ForegroundColor Red
}

if (Test-Path $routerPath) {
    Write-Host "  OK 路由配置存在" -ForegroundColor Green
} else {
    Write-Host "  XX 路由配置不存在" -ForegroundColor Red
}

if (Test-Path $dashboardPath) {
    Write-Host "  OK Dashboard页面存在" -ForegroundColor Green
} else {
    Write-Host "  XX Dashboard页面不存在" -ForegroundColor Red
}

Write-Host "`n测试完成!" -ForegroundColor Green